package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.materiel.MaterialVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by lzh on 2018/3/17.
 */

public class MaterialInfoAdapter extends LemonRcvAdapter<MaterialVo> {
    private RecyclerTClickListener<MaterialVo> mListener;

    public MaterialInfoAdapter(@Nullable List<MaterialVo> data, RecyclerTClickListener<MaterialVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new MaterialItem();
    }

    public class MaterialItem implements AdapterItem<MaterialVo> {

        @Bind(R.id.tv_space_name)
        TextView tvSpaceName;
        @Bind(R.id.iv_posion)
        ImageView ivPosion;
        @Bind(R.id.iv_easy_posion)
        ImageView ivEasyPosion;
        @Bind(R.id.iv_easy_bomb)
        ImageView ivEasyBomb;
        @Bind(R.id.iv_monitor)
        ImageView ivMonitor;
        @Bind(R.id.tv_material_type)
        TextView tvMaterialType;
        @Bind(R.id.tv_material_store_position)
        TextView tvMaterialStorePosition;
        @Bind(R.id.tv_material_store_metnod)
        TextView tvMaterialStoreMetnod;
        @Bind(R.id.tv_material_danger_type)
        TextView tvMaterialDangerType;
        @Bind(R.id.tv_material_danger_level)
        TextView tvMaterialDangerLevel;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;
        private MaterialVo data;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_material_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(MaterialVo materialVo, int position) {
            data = materialVo;
            pos = position;
            tvSpaceName.setText(CommonUtil.avoidNullString(materialVo.getName()));
            tvMaterialType.setText(CommonUtil.avoidNullString(materialVo.getType()));
            tvMaterialStorePosition.setText(CommonUtil.avoidNullString(materialVo.getPosition()));
            tvMaterialDangerLevel.setText(CommonUtil.avoidNullString(materialVo.getHazardous()));
            tvMaterialDangerType.setText(CommonUtil.avoidNullString(materialVo.getDangerousChemicals()));
            tvMaterialStoreMetnod.setText(CommonUtil.avoidNullString(materialVo.getStorageMode()));
            //是否剧毒
            if("是".equals(materialVo.getIsToxic())){
                ivPosion.setVisibility(View.VISIBLE);
            }else{
                ivPosion.setVisibility(View.GONE);
            }

            //易制毒
            if("是".equals(materialVo.getIsChemicals())){
                ivEasyPosion.setVisibility(View.VISIBLE);
            }else{
                ivEasyPosion.setVisibility(View.GONE);
            }

            //易制爆
            if("是".equals(materialVo.getIsBomb())){
                ivEasyBomb.setVisibility(View.VISIBLE);
            }else{
                ivEasyBomb.setVisibility(View.GONE);
            }

            //重点监管
            if("是".equals(materialVo.getIsSupervision())){
                ivMonitor.setVisibility(View.VISIBLE);
            }else{
                ivMonitor.setVisibility(View.GONE);
            }
        }
    }
}
